package utils

import "github.com/gin-gonic/gin"

type Response struct {
	Success      bool        `json:"success"`
	Data         interface{} `json:"data"`
	ErrorCode    int         `json:"errorCode"`
	ErrorMessage string      `json:"errorMessage"`
	ShowType     int         `json:"showType"`
}

type TableData struct {
	List     interface{} `json:"list"`
	Current  int         `json:"current"`
	PageSize int         `json:"pageSize"`
	Total    int         `json:"total"`
}

func ReturnResponse(c *gin.Context, success bool, data interface{}, errorCode int, errorMessage string, showType int) {
	json := &Response{
		Success:      success,
		Data:         data,
		ErrorCode:    errorCode,
		ErrorMessage: errorMessage,
		ShowType:     showType,
	}
	c.JSON(200, json)
}

func ReturnSuccess(c *gin.Context, data interface{}) {
	json := &Response{
		Success:      true,
		Data:         data,
		ErrorMessage: "操作成功",
		ShowType:     0,
	}
	c.JSON(200, json)
}

func ReturnError(c *gin.Context, data interface{}, errorCode int, errorMessage string, showType int) {
	json := &Response{
		Success:      false,
		Data:         data,
		ErrorCode:    errorCode,
		ErrorMessage: errorMessage,
		ShowType:     showType,
	}
	c.JSON(200, json)
}

func ReturnTableData(c *gin.Context, list interface{}, current int, pageSize int, total int) {
	tableData := &TableData{
		List:     list,
		Current:  current,
		PageSize: pageSize,
		Total:    total,
	}
	ReturnSuccess(c, tableData)
}
